Generating a password with a combination of letters, alphabets and special chars, by default it generates 10 chars.

================================================

function RandomPasswordGeneration($passwordlength=10)
 {
 	// add numbers,alphabets and special chars
  	$random_chars = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%";
        $getstring = "";
	$password= "";
	// While loop will execute until the length of password reaches the $passwordlength
        while(strlen($password)<$passwordlength) 
	{
		 // returns a sigle character from the set of random_chars
		 $getstring = substr($random_chars, mt_rand(0, strlen($random_chars)-1),1);
		
		 //Avoid already existed character from the password.
		 if (!strstr($password, $getstring)) 
		 {
		     //append the generated value to password 
    		     $password .= $getstring;
    	         }
           }
    return($password);
}

echo "Random Password ".RandomPasswordGeneration(); 
//if you need a length of 8 chars, send the paratmeter in function as RandomPasswordGeneration(8);